package proto

import (
	"strings"
	D "websocket_apn/define"

	"github.com/gorilla/websocket"
)

const (
	S_ATTRIBUTE_DREAM_LV_UP_SPEED_UP_By_Ads    = 1 //看广告升级仙树
	S_ATTRIBUTE_DREAM_LV_UP_SPEED_UP_By_Bottle = 2 //使用瓶子升级
)

type S_PLAYER_LOGIN_data struct {
	Token    string
	Language string
}

func Get_S_PLAYER_LOGIN_data(playerId int64) *D.Message {
	msg := &MsgData{
		Cmd:      S_PLAYER_LOGIN,
		PlayerID: playerId,
	}
	if _, ok := D.UserGameDataMap[playerId]; !ok {
		return nil
	}
	msg.Data = S_PLAYER_LOGIN_data{
		Token:    D.UserGameDataMap[playerId].UserInfo.Token,
		Language: "zh_cn",
	}
	sendData := &D.Message{
		MessageType:  websocket.BinaryMessage,
		PayloadBytes: EncodeMsgData(msg),
	}
	return sendData
}

func Get_Cmd_Data(playerId int64, cmd int32, Hex string) *D.Message {
	msg := &MsgData{
		Cmd:      cmd,
		PlayerID: playerId,
	}
	if len(Hex) > 1 {
		var data []byte
		data, _ = HexStrToBytes(strings.Replace(Hex, " ", "", -1))
		msg.HexData = data
	}
	//log.Debug("↑↑↑↑↑ %s - len:%d", GetGameCmdDesc(cmd), len(msg.HexData)+18)
	return &D.Message{
		MessageType:  websocket.BinaryMessage,
		PayloadBytes: EncodeMsgData(msg),
	}
}

func Get_Cmd_No_Data(playerId int64, cmd int32) *D.Message {
	msg := &MsgData{
		Cmd:      int32(cmd),
		PlayerID: playerId,
	}
	return &D.Message{
		MessageType:  websocket.BinaryMessage,
		PayloadBytes: EncodeMsgData(msg),
	}
}
